import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:miracle_recorder/bloc/auth/auth_bloc.dart';
import 'package:miracle_recorder/bloc/auth/auth_event.dart';
import 'package:miracle_recorder/screens/auth/login_screen.dart';
import 'package:miracle_recorder/screens/main/main_screen.dart';
import 'package:miracle_recorder/screens/splash_screen.dart';
import 'package:miracle_recorder/services/api_service.dart';
import 'package:miracle_recorder/services/storage_service.dart';
import 'package:miracle_recorder/theme/app_theme.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  // 初始化服务
  await StorageService.init();
  ApiService.init();
  
  runApp(const MiracleRecorderApp());
}

class MiracleRecorderApp extends StatelessWidget {
  const MiracleRecorderApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MultiBlocProvider(
      providers: [
        BlocProvider(
          create: (context) => AuthBloc()..add(CheckAuthStatus()),
        ),
      ],
      child: MaterialApp(
        title: '奇迹记录仪',
        debugShowCheckedModeBanner: false,
        theme: AppTheme.lightTheme,
        darkTheme: AppTheme.darkTheme,
        themeMode: ThemeMode.system,
        home: const SplashScreen(),
        routes: {
          '/login': (context) => const LoginScreen(),
          '/main': (context) => const MainScreen(),
        },
      ),
    );
  }
}